<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

	<link rel="stylesheet"
		href="../../css/bootstrap.min.css" />
	<title><h:outputText value="NP Pillar" /></title>
</h:head>
<h:body>

	<ui:insert name="header">
		<ui:include src="../template/header.xhtml" />
	</ui:insert>
	<h:form id="mainForm">
		<p:panel
			header="#{returnControler.editMode? 'Edit Sales Return Information' : 'Add Sales Return order'}">
			<p:panelGrid columns="2">
				<p:outputLabel value="Newspaper:" />
				<p:selectOneMenu
					value="#{returnControler.editDto.issue.newspaper.seq}"
					validator="#{newspaperControler.seqValidate}">
					<f:selectItem itemLabel="-- Select --" itemValue="0" />
					<f:selectItems var="newspaper"
						value="#{newspaperControler.baseList}"
						itemLabel="#{newspaper.name}" itemValue="#{newspaper.seq}" />
					<p:ajax listener="#{returnControler.clearIssue}" update="issueList" />
				</p:selectOneMenu>

				<p:outputLabel value="Issue Number:" />
				<p:selectOneMenu id="issueList"
					value="#{returnControler.editDto.issue.seq}"
					validator="#{issueControler.seqValidate}">
					<f:selectItem itemLabel="-- Select --" itemValue="0" />
					<f:selectItems value="#{returnControler.issueList}" var="issue"
						itemLabel="#{issue.formatIssue}" itemValue="#{issue.seq}" />
				</p:selectOneMenu>

				<p:outputLabel value="Unit Price:" />
				<p:spinner value="#{returnControler.editDto.unitPrice}" min="0.0"
					stepFactor="0.5">
					<p:ajax update="totalPrice payables" />
				</p:spinner>

				<p:outputLabel value="Quantity:" />
				<p:spinner value="#{returnControler.editDto.quantity}" min="1">
					<p:ajax update="totalPrice payables" />
				</p:spinner>

				<p:outputLabel value="Total Price:" />
				<p:outputLabel id="totalPrice"
					value="#{returnControler.editDto.money}" />

				<p:outputLabel value="Discount:" />
				<p:spinner value="#{returnControler.editDto.discount}" min="0.00"
					stepFactor="0.05">
					<p:ajax update="payables" />
				</p:spinner>

				<p:outputLabel value="Returned Money:" />
				<p:outputLabel id="payables"
					value="#{returnControler.editDto.payables}" />

				<p:outputLabel value="Responsible Person:" />
				<p:autoComplete value="#{returnControler.editDto.employee.name}"
					placeholder="Type for hint..."
					completeMethod="#{workInfoControler.completeEmployeeName}"
					required="true" requiredMessage="Responsible Person is required."
					validator="#{workInfoControler.nameValidate}" />

				<p:outputLabel value="Order Date:" />
				<p:calendar value="#{returnControler.editDto.orderDate}"
					navigator="true" pattern="yyyy-MM-dd" showOn="both" required="true"
					requiredMessage="Order Date is required." />

				<p:outputLabel value="Information Source" />
				<p:selectOneMenu filter="true" filterMatchMode="contains"
					value="#{returnControler.editDto.promotion.seq}"
					validator="#{promotionControler.seqValidate}">
					<f:selectItem itemLabel="-- Select --" itemValue="0" />
					<f:selectItems var="promotion"
						value="#{promotionControler.allList}"
						itemLabel="#{promotion.name}" itemValue="#{promotion.seq}" />
				</p:selectOneMenu>
			</p:panelGrid>
			<p:messages autoUpdate="true" />
			<p:commandButton value="Save"
				actionListener="#{returnControler.apply}"
				action="#{mainMenuControler.transfer}" onclick="blockui.show()"
				oncomplete="blockui.hide()">
				<f:setPropertyActionListener target="#{mainMenuControler.nextMenu}"
					value="/faces/sales/return.jsf" />
			</p:commandButton>
			<p:commandButton value="Cancel"
				actionListener="#{returnControler.clear}"
				action="#{mainMenuControler.transfer}" onclick="blockui.show()"
				oncomplete="blockui.hide()" immediate="true">
				<f:setPropertyActionListener target="#{mainMenuControler.nextMenu}"
					value="/faces/sales/return.jsf" />
			</p:commandButton>
		</p:panel>
	</h:form>
</h:body>
</html>
